package com.telewave.stompdemo.conf;

import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * RabbitMQ配置
 *
 * @author looveh
 * @since 2023/10/18 10:56:22
 **/
@Configuration
public class RabbitConfig {

    private static final String MY_TOPIC_EXCHANGE_NAME = "myTopicExchange";

    @Resource
    private ConnectionFactory rabbitConnectionFactory;

    @PostConstruct
    public void init(){
        RabbitAdmin rabbitAdmin = new RabbitAdmin(rabbitConnectionFactory);
        rabbitAdmin.declareExchange(myTopicExchange());
    }

    @Bean
    public TopicExchange myTopicExchange() {
        return new TopicExchange(MY_TOPIC_EXCHANGE_NAME);
    }
}
